/**
 * @file
 * @brief 基于VA-API方案的H264硬件加速编码
 */

#include "../../BaseEncoder.hpp"
#include <chrono>
#include <gst/app/app.h>
#include <gst/gst.h>

/**
 * @class Encoder
 * @brief 详细接口定义参见`BaseEncoder`
 * @note
 * 采用gstreamer，流结构为
 * appsrc->videoconvert->capsfliter->vah264enc->mpegtsmux->srtsink
 *
 */
class Encoder : public BaseEncoder {
private:
  friend void enough_data_callback(GstAppSrc *self, gpointer user_data);
  friend void need_data_callback(GstAppSrc *self, guint length,
                                 gpointer user_data);
  GstElement *pipeline;
  GstElement *appsrc, *videoconvert, *vah264enc, *mpegtsmux, *srtsink;
  GstBus *bus;
  bool status = false;
  long imageSize;
  std::chrono::steady_clock::time_point startTime;
  bool enoughDataFlag = false;

public:
  /**
   * @brief 构造函数
   */
  Encoder(const std::string &srturi);

  /**
   * @brief 析构函数
   */
  virtual ~Encoder();

  /**
   * @brief 开始串流
   */
  virtual void StartStream(int width, int height,
                           const ImageType &type) override;

  /**
   * @brief 输入图片
   */
  virtual void InputImage(const unsigned char *img) override;

  /**
   * @brief 流结束
   */
  virtual void EndStream() override;

  /**
   * @brief 获取状态
   */
  virtual bool GetStatus() override;
};
